
import React,{Component} from 'react';


class Test extends Component{
   
    constructor(props){
        super(props);
        console.log(this);
        //创建引用的对象
        this.myOneInputRef = React.createRef();
        this.myTwoInputRef = React.createRef();
    
    }

    handleClick=()=>{
       /*  let nodeObj = document.getElementById("test");
        let val =nodeObj.value;
        console.log(val) */
       console.log(this.myOneInputRef.current.value);
       console.log(this.myTwoInputRef.current.value);
       //this.myOneInputRef.current.value='one';
       //this.myTwoInputRef.current.value='two'
       //console.log(test.value);

    }

    render(){
        return(
            <div>
                <h3>Refs</h3>
                <input id='test' ref={this.myOneInputRef} ></input> 
                <input ref={this.myTwoInputRef}></input> 
                <button onClick={this.handleClick}>点击显示内容</button>
            </div>
        )
    }
}
export default Test